import 'dart:async';
import 'dart:ffi';

import 'package:flutter/material.dart';

class Utils {
  static int getYear() {
    return DateTime.now().year;
  }

  static int getMonth() {
    return DateTime.now().month;
  }

  static int getDay() {
    return DateTime.now().day;
  }

  // 时间
  // @return 返回星期
  static int dateTranslateWeek(int year, int month, int day) {
    return DateTime(year, month, day).weekday;
  }

  /**
   * 判断颜色深浅
   *
   * @param color 颜色
   * @return 返回黑色或者白色
   */
  static int colorDepth(int i) {
    HSVColor hsvColor = HSVColor.fromColor(Color(i));
    double c = hsvColor.hue * 0.299 +
        hsvColor.saturation * 0.587 +
        hsvColor.value * 0.114;
    if (c > 90 || c == 0) {
      return 0xFFFFFFFF;
    } else
      return 0xFF000000;
  }

  static void timeTask(int time, Function fun) {
    Timer.periodic(Duration(milliseconds: time), (timer) {
      fun();
      timer.cancel();
    });
  }
}
